<html>
<head><meta charset="utf-8"><title>using is_x86_feature_detected in std · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html">using is_x86_feature_detected in std</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="230101546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230101546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230101546">(Mar 12 2021 at 21:35)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
   --&gt; library/std/src/time.rs:30:5
    |
30  | use super::is_x86_feature_detected;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[deny(macro_expanded_macro_exports_accessed_by_absolute_paths)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #52234 &lt;https://github.com/rust-lang/rust/issues/52234&gt;
note: the macro is defined here
   --&gt; library/std/src/../../stdarch/crates/std_detect/src/detect/macros.rs:14:9
</code></pre></div>



<a name="230101598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230101598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230101598">(Mar 12 2021 at 21:35)</a>:</h4>
<p>What's the correct way to <code>use</code> the macro inside std?</p>



<a name="230101753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230101753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230101753">(Mar 12 2021 at 21:36)</a>:</h4>
<blockquote>
<p>#[macro_export] macro_rules items are collected from the whole crate and are planted into the root module as items, so the external view of the crate is symmetric with its internal view and something like $crate::my_macro where my_macro is #[macro_export] macro_rules works both locally and from other crates.</p>
</blockquote>
<p>I think you want <code>use crate::is_feature_detected</code> (not <code>super::</code>)</p>



<a name="230102035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230102035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230102035">(Mar 12 2021 at 21:38)</a>:</h4>
<p>You mean <code>use crate::is_x86_feature_detected;</code>? tried that, same error.</p>



<a name="230102079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230102079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230102079">(Mar 12 2021 at 21:38)</a>:</h4>
<p>what happens if you use it without importing it?</p>



<a name="230102143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230102143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230102143">(Mar 12 2021 at 21:39)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error: cannot find macro `is_x86_feature_detected` in this scope
   --&gt; library/std/src/time.rs:306:65
    |
306 |             if crate::mem::size_of::&lt;time::Instant&gt;() == 128 &amp;&amp; is_x86_feature_detected!(&quot;cmpxchg16b&quot;) {
    |                                                                 ^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: consider importing this macro:
            crate::is_x86_feature_detected
    = help: have you added the `#[macro_use]` on the module/import?
</code></pre></div>



<a name="230103683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230103683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230103683">(Mar 12 2021 at 21:51)</a>:</h4>
<p><code>::is_x86_feature_detected!()</code>?</p>



<a name="230103857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230103857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230103857">(Mar 12 2021 at 21:53)</a>:</h4>
<p>But yes, you want to refer to the macro without involving <code>use</code>, I think,</p>



<a name="230107226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230107226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230107226">(Mar 12 2021 at 22:10)</a>:</h4>
<p><code>::is_x86_feature_detected!()</code> doesn't resolve. invoking <code>crate::...</code> or <code>super::...</code> directly without <code>use</code> returns the same macro_expanded_macro_exports_accessed_by_absolute_paths warning/error.</p>



<a name="230111878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230111878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230111878">(Mar 12 2021 at 22:45)</a>:</h4>
<p>That's quite a puzzle.  The only solution I can think of is to sprinkle <code>#[macro_use]</code> on the std_detect modules, but then the macro will only be visible textually after <code>std_detect</code>, so it will be very difficult to use.</p>



<a name="230112144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230112144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230112144">(Mar 12 2021 at 22:47)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> may be able to suggest something.</p>



<a name="230128371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230128371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230128371">(Mar 13 2021 at 02:33)</a>:</h4>
<p>hm, is this for optimizing <code>std::time::Instant</code>? you'd probably be better by explicitly doing this either in the way the (darwin/windows) std::time modules cache their timebase, and on non-darwin unix synchronizing on an acq/rel of the <code>seconds</code> field of the struct timespec.</p>



<a name="230153466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230153466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230153466">(Mar 13 2021 at 10:23)</a>:</h4>
<p>It's for backslide protection which currently uses a lock.  I don't think this can be achieved with atomic ops on just one of the fields.</p>



<a name="230156527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230156527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230156527">(Mar 13 2021 at 11:27)</a>:</h4>
<p>Does adding a <code>pub use is_x86_feature_detected</code> <em>right after its definition point</em> and then using a full path pointing there work?</p>



<a name="230156688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230156688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230156688">(Mar 13 2021 at 11:30)</a>:</h4>
<p>What I mean is that something like this works:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">mod</span> <span class="nn">macros</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="fm">macro_rules!</span><span class="w"> </span><span class="n">mk_m</span><span class="w"> </span><span class="p">{()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">(</span><span class="w"></span>
<span class="w">        </span><span class="cp">#[macro_export]</span><span class="w"></span>
<span class="w">        </span><span class="fm">macro_rules!</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="p">{()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">()}</span><span class="w"></span>
<span class="w">    </span><span class="p">)}</span><span class="w"></span>
<span class="w">    </span><span class="n">mk_m</span><span class="o">!</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">use</span><span class="w"> </span><span class="n">m</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">mod</span> <span class="nn">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">super</span>::<span class="n">macros</span>::<span class="n">m</span><span class="o">!</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="230163360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230163360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230163360">(Mar 13 2021 at 13:38)</a>:</h4>
<p>Why does the definition of <code>is_x86_feature_detected</code> come from a macro?</p>



<a name="230163399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230163399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230163399">(Mar 13 2021 at 13:39)</a>:</h4>
<p>The least hacky and unobvious fix for this issue is to not generate <code>#[macro_export]</code> items with macros.</p>



<a name="230166147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230166147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230166147">(Mar 13 2021 at 14:28)</a>:</h4>
<p><span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> the inner macro's name depends on an argument passed to the outer macro. <code>std_detect</code> generates <code>is_{arch}_feature_detected</code> that way.</p>



<a name="230167353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230167353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230167353">(Mar 13 2021 at 14:51)</a>:</h4>
<p>What I mean is that</p>
<div class="codehilite" data-code-language="Diff"><pre><span></span><code>  }
<span class="gi">+ pub use $macro_name;</span>
</code></pre></div>
<p>could be applied to <a href="https://github.com/rust-lang/stdarch/blob/9c732a56f67f54d12a0b4fd99993154906c95ea6/crates/std_detect/src/detect/macros.rs#L44">https://github.com/rust-lang/stdarch/blob/9c732a56f67f54d12a0b4fd99993154906c95ea6/crates/std_detect/src/detect/macros.rs#L44</a> (should the macro need to be <code>#[macro_export]</code>ed), and from there you'd have a "usable" (modulo privacy, but that's easy to fix with another re-export) absolute path.</p>
<p>The other option would be to improve a bit the duck typing of that <code>mod.rs</code> file inside <code>std_detect</code>: you could use a <code>cfg(standalone_std_detect)</code> to apply the attributes necessary for that code to operate as a standalone crate (<em>e.g.</em>, <code>#[cfg_attr(standalone_std_detect, macro_export)]</code>, which would be possible by having the <code>build.rs</code> of that crate emit that cfg. That way, when <code>::std</code> does that <code>#[path = "…"] mod std_detect;</code> hack, the cfg wouldn't be enabled, and you wouldn't have to worry about misinteractions between a private user (<code>::std</code> code) and a no-longer-happening export of macros.</p>



<a name="230172670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230172670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230172670">(Mar 13 2021 at 16:13)</a>:</h4>
<p>Ah, yes, that seems to work. <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="230938873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230938873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230938873">(Mar 18 2021 at 21:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span> <a href="#narrow/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std/near/230128371">said</a>:</p>
<blockquote>
<p>hm, is this for optimizing <code>std::time::Instant</code>? you'd probably be better by explicitly doing this either in the way the (darwin/windows) std::time modules cache their timebase, and on non-darwin unix synchronizing on an acq/rel of the <code>seconds</code> field of the struct timespec.</p>
</blockquote>
<p>Having looked through the platform implementations you might be right after all, it looks like some are deriving their Instant from 64bit values but convert them to 128bit ones fairly early. Wouldn't help the BSDs though which do the same as linux and aren't <code>actually_monotonic()</code>. So we'd need the 64 and 128bit atomics. Ugh.</p>



<a name="230944803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/using%20is_x86_feature_detected%20in%20std/near/230944803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/using.20is_x86_feature_detected.20in.20std.html#230944803">(Mar 18 2021 at 22:05)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/83278">#83278</a> will change <code>std_detect</code> to be a separate crate, which should solve this issue.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>